/*#pragma once
#include <iostream>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "Log.hpp"
#include"Common.hpp"
#include"InetAddr.hpp"

namespace SocketModule
{
    using namespace LogModule;
    class Socket
    {
    public:
        Socket() {}
        virtual ~Socket() {}
        virtual void SocketOrDie() = 0;       // 创建socket套接字
        virtual bool BindOrDie(int port) = 0; // 绑定端口号
        virtual bool ListenOrDie() = 0;
    };

    class TcpSocket : public Socket
    {
    public:
        TcpSocket()
        {
        }
        virtual ~TcpSocket() override
        {
        }
        virtual void SocketOrDie() override
        {
            int _socket = ::socket(AF_INET, SOCK_STREAM, 0);
            if (_socket < 0)
            {
                LOG(LogLevel::ERROR) << "socket error";
            }
            else
            {
                LOG(LogLevel::INFO) << "create socket success";
            }
        }

        virtual bool BindOrDie(int port) override
        {
            InetAddr peer = InetAddr(port);
            int n = ::bind(_socket, CONV(&peer), peer.NetAddrLen());
            if (n < 0)
            {
                LOG(LogLevel::ERROR) << "bind error";
                exit(SOCKET_ERR);
            }
            LOG(LogLevel::DEBUG) << "bind create success: " << _socket;
            return true;
        }

        virtual bool ListenOrDie()override//进行监听
        {
            int n = ::listen(_socket,gbacklog);
            if(n<0)
            {
                LOG(LogLevel::ERROR) << "listen error";
                exit(SOCKET_ERR);
            }

        }
        private:
        int _socket;
    };

}*/
#include <iostream>
#include "InetAddr.hpp"

int main() {
    struct sockaddr_in clientAddr;
    clientAddr.sin_family = AF_INET;
    clientAddr.sin_port = htons(12345); // 网络字节序的端口号
    clientAddr.sin_addr.s_addr = inet_addr("192.168.1.100"); // 网络字节序的 IP 地址

    InetAddr addr;
    socklen_t len = sizeof(clientAddr);
    addr.SetAddr(clientAddr, len);

    std::cout << "IP: " << addr.Ip() << std::endl;
    std::cout << "Port: " << addr.Port() << std::endl;
    std::cout << "Address: " << addr.Addr() << std::endl;

    return 0;
}
